package com.ruoyi.service.impl;

import java.util.List;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.domain.AbilityServer;
import com.ruoyi.mapper.AbilityServerMapper;
import com.ruoyi.service.IAbilityServerService;
import com.ruoyi.service.ServiceKong;
import com.ruoyi.utils.Check;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.*;


/**
 * 代理服务Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-19
 */
@Service
public class AbilityServerServiceImpl implements IAbilityServerService
{
    @Autowired
    private AbilityServerMapper abilityServerMapper;
    @Autowired
    ServiceKong service;
    @Override
    public int changeHost(AbilityServer abilityServer) {
        AbilityServer info = abilityServerMapper.selectAbilityServerByID(abilityServer.getID());
        JSONObject res = new JSONObject();
        abilityServer.setSName(info.getSName());
        System.out.println(abilityServer.getSName());
        res=service.patchServiceHost(abilityServer.getSName(),abilityServer.getSHost());

        if(Check.CheckIsSuccess(res)){
            return abilityServerMapper.updateAbilityServer(abilityServer);
        }
        return -1;
    }

    /**
     * 查询代理服务
     * 
     * @param ID 代理服务主键
     * @return 代理服务
     */
    @Override
    public AbilityServer selectAbilityServerByID(String ID)
    {
        return abilityServerMapper.selectAbilityServerByID(ID);
    }

    /**
     * 查询代理服务列表
     * 
     * @param abilityServer 代理服务
     * @return 代理服务
     */
    @Override
    public List<AbilityServer> selectAbilityServerList(AbilityServer abilityServer)
    {
        return abilityServerMapper.selectAbilityServerList(abilityServer);
    }

    /**
     * 新增代理服务
     * 
     * @param abilityServer 代理服务
     * @return 结果
     */
    @Override
    public int insertAbilityServer(AbilityServer abilityServer)
    {
        return abilityServerMapper.insertAbilityServer(abilityServer);
    }

    /**
     * 修改代理服务
     * 
     * @param abilityServer 代理服务
     * @return 结果
     */
    @Override
    public int updateAbilityServer(AbilityServer abilityServer)
    {
        return abilityServerMapper.updateAbilityServer(abilityServer);
    }

    /**
     * 批量删除代理服务
     * 
     * @param IDs 需要删除的代理服务主键
     * @return 结果
     */
    @Override
    public int deleteAbilityServerByIDs(String[] IDs)
    {
        return abilityServerMapper.deleteAbilityServerByIDs(IDs);
    }

    /**
     * 删除代理服务信息
     * 
     * @param ID 代理服务主键
     * @return 结果
     */
    @Override
    public int deleteAbilityServerByID(String ID)
    {
        return abilityServerMapper.deleteAbilityServerByID(ID);
    }
}
